package api

import (
	"gitee.com/DengAnbang/Wefore/src/bean"
	"gitee.com/DengAnbang/Wefore/src/dbops"
	"gitee.com/DengAnbang/Wefore/src/fun"
	"gitee.com/DengAnbang/goutils/httpUtils"
	"net/http"
)

/**
* showdoc
* @catalog 接口文档/组织结构树
* @title 创建节点
* @description 创建节点的接口
* @method socket type=301
* @url /pc/structure/treeNode/create
* @param userId 必选 string 创建人的id
* @param nodeName 必选 string 节点名
* @param nodeParentId 选填 string 父节点ID(不填就是新树)
* @return {"code":0,"type":0,"message":"","debug_message":"","data":StructureTreeBean}
* @remark nodeParentId不填就是新树
* @number 1
 */
func StructureTreeNodeCreateHttp(_ http.ResponseWriter, r *http.Request) error {
	userId := httpUtils.GetValueFormRequest(r, "userId")
	nodeName := httpUtils.GetValueFormRequest(r, "nodeName")
	nodeParentId := httpUtils.GetValueFormRequest(r, "nodeParentId")
	node, err := dbops.StructureTreeNodeCreate(userId, nodeName, nodeParentId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(node)
}
func StructureTreeNodeCreateSocket(parameters map[string]interface{}) error {
	userId := fun.GetString(parameters, "userId")
	nodeName := fun.GetString(parameters, "nodeName")
	nodeParentId := fun.GetString(parameters, "nodeParentId")
	node, err := dbops.StructureTreeNodeCreate(userId, nodeName, nodeParentId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(node)
}

/**
* showdoc
* @catalog 接口文档/组织结构树
* @title 删除节点
* @description 删除节点的接口
* @method socket type=302
* @url /pc/structure/treeNode/delete
* @param nodeId 必选 nodeId 节点ID
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"删除成功"}
* @remark
* @number 2
 */
func StructureTreeNodeDeleteHttp(_ http.ResponseWriter, r *http.Request) error {
	nodeId := httpUtils.GetValueFormRequest(r, "nodeId")
	err := dbops.StructureTreeNodeDelete(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("删除成功")
}
func StructureTreeNodeDeleteSocket(parameters map[string]interface{}) error {
	nodeId := fun.GetString(parameters, "nodeId")
	err := dbops.StructureTreeNodeDelete(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("删除成功")
}

/**
* showdoc
* @catalog 接口文档/组织结构树
* @title 修改节点和设置负责人
* @description 修改节点的接口(仅仅修改名字)
* @method socket type=303
* @url /pc/structure/treeNode/update
* @param nodeId 必选 string 节点ID
* @param nodeName 选填 string 节点的新名字
* @param headUserId 选填 string 负责人的id
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"修改成功"}
* @remark 修改的时候，必须两个值都传
* @number 3
 */
func StructureTreeNodeUpdateHttp(_ http.ResponseWriter, r *http.Request) error {
	nodeId := httpUtils.GetValueFormRequest(r, "nodeId")
	nodeName := httpUtils.GetValueFormRequest(r, "nodeName")
	headUserId := httpUtils.GetValueFormRequest(r, "headUserId")
	err := dbops.StructureTreeNodeUpdate(nodeId, nodeName, headUserId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("修改成功")
}
func StructureTreeNodeUpdateSocket(parameters map[string]interface{}) error {
	nodeId := fun.GetString(parameters, "nodeId")
	nodeName := fun.GetString(parameters, "nodeName")
	headUserId := fun.GetString(parameters, "headUserId")
	err := dbops.StructureTreeNodeUpdate(nodeId, nodeName, headUserId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("修改成功")
}

/**
* showdoc
* @catalog 接口文档/组织结构树
* @title 查询节点(一层)
* @description 查询节点的接口(仅仅查询当前节点的子)
* @method socket type=304
* @url /pc/structure/treeNode/select/child
* @param nodeId 必选 nodeId 节点ID
* @return {"code":0,"type":0,"message":"","debug_message":"","data":[]StructureTreeBean}
* @remark
* @number 4
 */
func StructureTreeChildNodeSelectHttp(_ http.ResponseWriter, r *http.Request) error {
	nodeId := httpUtils.GetValueFormRequest(r, "nodeId")
	beans, err := dbops.StructureTreeChildNodeSelect(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}
func StructureTreeChildNodeSelectSocket(parameters map[string]interface{}) error {
	nodeId := fun.GetString(parameters, "nodeId")
	beans, err := dbops.StructureTreeChildNodeSelect(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}

/**
* showdoc
* @catalog 接口文档/组织结构树
* @title 查询节点(所有子)
* @description 查询节点的接口(查询当前节点的所有子)
* @method socket type=305
* @url /pc/structure/treeNode/select/child/all
* @param nodeId 必选 string 节点ID
* @return {"code":0,"type":0,"message":"","debug_message":"","data":[]StructureTreeBean}
* @remark
* @number 5
 */
func StructureTreeChildNodeSelectAllHttp(_ http.ResponseWriter, r *http.Request) error {
	nodeId := httpUtils.GetValueFormRequest(r, "nodeId")
	beans, err := dbops.StructureTreeChildNodeSelectAll(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}
func StructureTreeChildNodeSelectAllSocket(parameters map[string]interface{}) error {
	nodeId := fun.GetString(parameters, "nodeId")
	beans, err := dbops.StructureTreeChildNodeSelectAll(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}
